package org.beangle.notification.service

import java.util.ArrayList
import java.util.List
import java.util.Queue
import java.util.concurrent.LinkedBlockingQueue
import org.beangle.notification.Message
import org.beangle.notification.MessageQueue
//remove if not needed
import scala.collection.JavaConversions._

class DefaultMessageQueue[T <: Message] extends MessageQueue[T] {

  private var queue: Queue[T] = new LinkedBlockingQueue[T]()

  def getMessages(): List[T] = new ArrayList[T](queue)

  def addMessage(message: T) {
    queue.add(message)
  }

  def addMessages(contexts: List[T]) {
    queue.addAll(contexts)
  }

  def poll(): T = queue.poll().asInstanceOf[T]

  def size(): Int = queue.size
}
